package wzy.com.iconfont;

import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 加载字体文件
        Typeface iconfont = Typeface.createFromAsset(getAssets(), "iconfonts/iconfont.ttf");
        final TextView mail = (TextView) findViewById(R.id.mail);
        // 设置 typeface, 就是字体文件
        mail.setTypeface(iconfont);
        final int[] colorRes = new int[]{R.color.black, R.color.red, R.color.green, R.color.blue,
                R.color.yellow, R.color.cyan, R.color.magenta, R.color.gray,
                R.color.ltgray, R.color.dkgray, R.color.gold, R.color.light_blue};
        final int[] strRes = new int[]{R.string.q, R.string.w, R.string.e, R.string.r, R.string.t, R.string.y,
                R.string.u, R.string.i, R.string.o, R.string.p, R.string.a, R.string.s};
        final Random random = new Random();// 定义随机类
        mail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int randomColor = random.nextInt(12);
                int randomStr = random.nextInt(12);
                mail.setTextColor(getColor(colorRes[randomColor]));
                mail.setText(strRes[randomStr]);
            }
        });
    }
}
